Imports System.Data
Imports ProfileCommon
Partial Class GTSWeb_Carrier_Manage
    Inherits System.Web.UI.Page


    Protected Sub linkAddSurcharge_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
                                            Handles linkAddSurcharge.Click
        If txtExtraCharge.Text.Trim = "" Then
            eMessage.Text = "Missing required field"
        Else
            Try
                Dim RateLogic As New GTSSystem.BLL.Rates
                RateLogic.AddRateSurcharge(gdvwRateID.SelectedValue, ddlSurcharge.SelectedValue, txtExtraCharge.Text, ddlChargeType.Text)
                Clear()
                Message.Text = "Surcharge added successfully"
                pSurcharge.Visible = True
                Response.Redirect(Request.Url.ToString)
            Catch ex As Exception
                Message.Text = "Unable to add surcharge."
            End Try
        End If
    End Sub

    Public Sub Clear()
        txtExtraCharge.Text = ""
        Message.Text = ""
        ddlSurcharge.SelectedIndex = -1
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim RateLogic As New GTSSystem.BLL.Rates()
        Dim MyData As DataTable
        Dim MyTable As New DataTable("ContractRates")
        MyTable.Columns.Add("RateID", GetType(String))
        MyTable.Columns.Add("Carrier", GetType(String))
        MyTable.Columns.Add("Origin", GetType(String))
        MyTable.Columns.Add("Destination", GetType(String))
        MyTable.Constraints.Add("Key1", MyTable.Columns(0), True)
        Dim user As MembershipUser = Membership.GetUser
        Dim p As ProfileCommon = ProfileCommon.Create(user.UserName)
        Try
            MyData = RateLogic.GetRateByBranchID(p.BranchId)
            If MyData.Rows.Count > 0 Then
                For n As Integer = 0 To MyData.Rows.Count - 1
                    Dim RateID As Integer = MyData.Rows(n).Item("RateID")
                    Dim ContractID As Integer = MyData.Rows(n).Item("ContractID")
                    Dim Origin As Integer = MyData.Rows(n).Item("Origin")
                    Dim Destination As Integer = MyData.Rows(n).Item("Destination")
                    Dim OData As DataTable
                    Dim DData As DataTable
                    Dim CData As DataTable
                    Dim ContractInfoLogic As New GTSSystem.BLL.Contract()
                    CData = ContractInfoLogic.GetContractInfoByContractID(ContractID)
                    Dim CarrierName As String = CData.Rows(0).Item("CarrierName")
                    Dim LocationLogic As New GTSSystem.BLL.RateLocation()
                    OData = LocationLogic.GetRateLocationByRateLocationID(Origin)
                    DData = LocationLogic.GetRateLocationByRateLocationID(Destination)
                    Dim OCity As String = OData.Rows(0).Item("City")
                    Dim OProv As String = OData.Rows(0).Item("Province")
                    Dim DCity As String = DData.Rows(0).Item("City")
                    Dim DProv As String = DData.Rows(0).Item("Province")
                    Dim aRow As DataRow
                    aRow = MyTable.NewRow
                    aRow.Item("RateID") = RateID
                    aRow.Item("Carrier") = CarrierName
                    aRow.Item("Origin") = OCity + ", " + OProv
                    aRow.Item("Destination") = DCity + ", " + DProv
                    MyTable.Rows.Add(aRow)
                Next
                gdvwRateID.DataSource = MyTable
                gdvwRateID.DataBind()
            End If
        Catch ex As Exception

        End Try
    End Sub

End Class
